package com.undsf.utility;

import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by Arathi on 2016/10/15.
 */
public class TemplateEngine {
    public static String Parse(String template, Map<String,String> paramDict) {
        // StringBuffer parsed = new StringBuffer(template);
        String parsed = new String(template);
        for (String paramName : paramDict.keySet()) {
            String regex = "\\$\\{" + paramName + "\\}";
            Pattern pattern = Pattern.compile(regex);
            Matcher matcher = pattern.matcher(parsed);
            boolean found = matcher.find();
            if (found) {
                String paramValue = paramDict.get(paramName);
                parsed = parsed.replaceAll(regex, paramValue);
            }
        }
        return parsed.toString();
    }
}
